import BpmnModeler from "bpmn-js/lib/Modeler";
import { unref } from "vue";
import Modeling from "bpmn-js/lib/features/modeling/Modeling";
import ElementRegistry from 'diagram-js/lib/core/ElementRegistry'

export class BpmnUtil {
  constructor(bpmnModeler) {
    this.bpmnModeler = bpmnModeler;
  }

  isMultiInstanceUserTask(element) {
    const bo = unref(element)?.businessObject
    return !!bo?.loopCharacteristics
  }

  updateProperty(element, properties) {
    const modeling = unref(this.bpmnModeler)?.get("modeling")
    modeling?.updateProperties(unref(element), properties)
  }

  updateModelingProperty(element, attrInstance, properties) {
    const modeling = this.bpmnModeler.value?.get("modeling")
    modeling?.updateModdleProperties(unref(element), attrInstance, properties)
  }

  getProcessKey() {
    const registry = unref(this.bpmnModeler)?.get("elementRegistry")
    const root = registry?.find(it => it.type === 'bpmn:Process')
    return root?.id || ''
  }
} 